home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1999 Spring / macformat-077.iso / Shareware Plus / Development / Akua Sweets 131 / Akua Sweets Examples / Resource / Extract Resources < prev    next >
Encoding:
Text File  |  1999-03-04  |  1.7 KB  |  67 lines  |  [TEXT/ToyS]

  1. property kasOutType : "RSRC" -- Picture file type
  2. property kasOutApp : "Doug" -- Creator for output file
  3. property gasResType : "TEXT" -- Default type to get
  4.  
  5.  
  6. on run
  7.     open {choose file with prompt "Choose a file to extract resources from…"}
  8. end run
  9.  
  10.  
  11. on open fsObjs
  12.     set gasResType to the text returned of (display dialog ¬
  13.         ("What type of resource would you like to collect?" & return & ¬
  14.             return & "(Enter the four letter resource type)") ¬
  15.             default answer gasResType with icon note ¬
  16.         buttons {"Cancel", "OK"} default button 2)
  17.     
  18.     set fsObj to item 1 of fsObjs
  19.     set fname to (catalog name of (basic info for fsObj))
  20.     set outFile to a new file in fsObj named fname & "•" & gasResType ¬
  21.         of type kasOutType with creator kasOutApp with resource fork
  22.     
  23.     repeat with fsObj in fsObjs
  24.         DoFile(fsObj, outFile)
  25.     end repeat
  26. end open
  27.  
  28.  
  29. on DoFile(fsObj, outFile)
  30.     set fname to catalog name of (basic info for fsObj)
  31.     set rsrcs to (the number of resources in fsObj of type gasResType with their info)
  32.     
  33.     set n to the number of items in rsrcs
  34.     set pg to display progress titled fname maximum n
  35.     
  36.     -- {{rName, rNum, rFlags}, {...}}
  37.     repeat with r in rsrcs
  38.         -- Get resource
  39.         set gotOne to true
  40.         try
  41.             set rsrc to the resource in fsObj of type gasResType ¬
  42.                 numbered (item 2 of r)
  43.         on error
  44.             display progress pg labeled ("Error reading: " & (item 2 of r))
  45.             set gotOne to false
  46.         end try
  47.         
  48.         if (gotOne) then
  49.             -- Name?
  50.             copy item 1 of r to rName
  51.             if (rName is "") then set rName to fname & "#" & (item 2 of r)
  52.             
  53.             -- Update progress        
  54.             display progress pg value 0 subtitled rName
  55.             
  56.             -- Write to outfile
  57.             save resource rsrc in outFile ¬
  58.                 of type gasResType ¬
  59.                 named rName
  60.         end if
  61.     end repeat
  62.     
  63.     display progress pg with disposal
  64. end DoFile
  65.  
  66.  
  67.